﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IService.Business;
using IService.DataDLL.Utility;
using IService.Model;
using IService.Utility;
using IService.DataDLL;

namespace IService.User_center
{
    public partial class ActivityList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                this.BindData();
            }
        }

        public void BindData()
        {
            //DataTable table = DTVBusiness.ActivityManager.GetLatestActivityList(5);
            //this.rptActivityList.DataSource = table;
            //this.rptActivityList.DataBind();

            PagingEntity pe = new PagingEntity("Activity", "UpdateDateTime desc");
            pe.PageSize = Pagination.PageSize;
            pe.PageIndex = Pagination.PageIndex;
            //pe.WhereClause = string.Format("type={0} and  RequestType={1} ", DetailType, TotalType);

            DataTable table = DTVBusiness.ActivityManager.GetActivityListPagin(pe);
            this.rptActivityList.DataSource = table;
            this.rptActivityList.DataBind();
            this.Pagination.BindName = "BindData";
            this.Pagination.Count = pe.RecordCount;
            this.Pagination.BindPager();
        }

        protected string GetShortContent(string content)
        {
            return StringUtil.GetShortContent(content, 40);
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string strOpinion = txtOpinion.Text;
            //检查信息是否完整
            if (string.IsNullOrEmpty(strOpinion))
            {
                this.lblErrorSupply.Text = "<font color='red'>请填写您想展开哪些活动！</font>";
            }
            else
            {
                ActivityOpinion opinion = new ActivityOpinion();
                opinion.UserId = SessionState.CurrentUser.ID;
                opinion.Opinion = strOpinion;
                opinion.UpdateDateTime = DateTime.Now;

                bool hassuccess = opinion.Save();
                if (hassuccess)
                {  
                    JsUtil.AlertAndRedirect("您的意见提交成功！", "ActivityList.aspx", this.Page);
                }
                else
                {
                    JsUtil.Alert("您的意见提交失败,请重新操作！", this.Page);
                }
            }
        }
    }
}